From fef24548b71177fe145bf5bac34348eda7878e09 Mon Sep 17 00:00:00 2001 From: robertl Date: Fri, 9 Apr 2004 16:13:37 +0000 Subject: [PATCH] Fix zero init of struct WAY (again). 1) snlen suboption now allows forced shortname lengths. 2) snwhite suboption now allows generated shortnames to contain no whitespace. 3) icons are now mapped by geocache type, just as with Mapsource. 4) Waypoint comment now contains difficulty and terrain when available. 5) I added ascii dump of data written to the Garmins in addition to hex. --- gpsbabel/Makefile | 4 ++-- gpsbabel/garmin.c | 43 ++++++++++++++++++++++++++++++++++------ gpsbabel/jeeps/gpsmem.c | 14 +++++++++++-- gpsbabel/jeeps/gpssend.c | 16 +++++++++++++++ gpsbabel/testo | 2 ++ 5 files changed, 69 insertions(+), 10 deletions(-) diff --git a/gpsbabel/Makefile b/gpsbabel/Makefile index e41dbd80c..c94be6384 100644 --- a/gpsbabel/Makefile +++ b/gpsbabel/Makefile @@ -78,8 +78,8 @@ dep: (echo -n "internal_styles.c: mkstyle.sh " ; echo style/*.style ; /bin/echo -e '\t./mkstyle.sh > $@ || (rm -f $@ ; exit 1)' ) >> /tmp/dep echo Edit Makefile and bring in /tmp/dep -VERSIONU=1_2_3_beta04052004 -VERSIOND=1.2.3_beta04052004 +VERSIONU=1_2_3_beta04072004 +VERSIOND=1.2.3_beta04072004 #VERSIONU=1_2_2 #VERSIOND=1.2.2 diff --git a/gpsbabel/garmin.c b/gpsbabel/garmin.c index adc891c2c..c33d654ed 100644 --- a/gpsbabel/garmin.c +++ b/gpsbabel/garmin.c @@ -34,11 +34,18 @@ static GPS_PTrack *tx_tracklist; static GPS_PTrack *cur_tx_tracklist_entry; static char *getposn; static char *poweroff; +static char *snlen; +static char *snwhiteopt; static arglist_t garmin_args[] = { - { "get_posn", &getposn, "Return current position as a waypoint", ARGTYPE_BOOL}, - { "power_off", &poweroff, "Command unit to power itself down", ARGTYPE_BOOL}, + { "snlen", &snlen, "Length of generated shortnames", ARGTYPE_INT }, + { "snwhite", &snwhiteopt, "(0/1) Allow whitespace synth. shortnames", + ARGTYPE_BOOL}, + { "get_posn", &getposn, "Return current position as a waypoint", + ARGTYPE_BOOL}, + { "power_off", &poweroff, "Command unit to power itself down", + ARGTYPE_BOOL}, { 0, 0, 0, 0} }; @@ -114,7 +121,17 @@ rw_init(const char *fname) break; } - setshort_length(mkshort_handle, short_length); + /* + * If the user provided a short_length, override the calculated value. + */ + if (snlen) + setshort_length(mkshort_handle, atoi(snlen)); + else + setshort_length(mkshort_handle, short_length); + + if (snwhiteopt) + setshort_whitespace_ok(mkshort_handle, atoi(snwhiteopt)); + setshort_mustupper(mkshort_handle, 1); } @@ -373,6 +390,7 @@ waypoint_write(void) extern queue waypt_head; GPS_PWay *way; extern int32 gps_save_id; + int icon; way = xcalloc(n,sizeof(*way)); @@ -385,6 +403,7 @@ waypoint_write(void) waypoint *wpt; char *ident; char *src = NULL; + char obuf[256]; wpt = (waypoint *) elem; @@ -403,12 +422,24 @@ waypoint_write(void) xfree(ident); } way[i]->ident[sizeof(way[i]->ident)-1] = 0; - if (src && strlen(src)) { - memcpy(way[i]->cmnt, src, strlen(src)); + + if (wpt->gc_data.diff && wpt->gc_data.terr) { + snprintf(obuf, sizeof(obuf), "%d/%d %s", + wpt->gc_data.diff, wpt->gc_data.terr, + src); + memcpy(way[i]->cmnt, obuf, strlen(obuf)); + } else { + memcpy(way[i]->cmnt, obuf, strlen(src)); } way[i]->lon = wpt->longitude; way[i]->lat = wpt->latitude; - way[i]->smbl = mps_find_icon_number_from_desc(wpt->icon_descr, PCX); + + if (get_cache_icon(wpt)) { + icon = mps_find_icon_number_from_desc(get_cache_icon(wpt), PCX); + } else { + icon = mps_find_icon_number_from_desc(wpt->icon_descr, PCX); + } + way[i]->smbl = icon; if (wpt->altitude != unknown_alt) { way[i]->alt = wpt->altitude; } diff --git a/gpsbabel/jeeps/gpsmem.c b/gpsbabel/jeeps/gpsmem.c index 48bc461af..0ba1ec59c 100644 --- a/gpsbabel/jeeps/gpsmem.c +++ b/gpsbabel/jeeps/gpsmem.c @@ -225,7 +225,7 @@ GPS_PWay GPS_Way_New(void) GPS_PWay ret; int32 i; - if(!(ret=(GPS_PWay)malloc(sizeof(GPS_OWay)))) + if(!(ret=(GPS_PWay)xcalloc(sizeof(GPS_OWay),1))) { perror("malloc"); fprintf(stderr,"GPS_Way_New: Insufficient memory"); @@ -233,10 +233,19 @@ GPS_PWay GPS_Way_New(void) return NULL; } + /* + * It turns out that the Way struct, initialized with zeros (not the + * random stuff that we got with malloc, but REALLY initialized with + * zeros from the calloc above actually does use C strings and it's + * up to the various way_blah_send functions to zero/string pad things + * as it goes. So neutralize this. + */ +#if 0 + /* * Mark all as "unused". These appear in the same order as in the struct. */ -#define BLANK(x) memset(x, ' ',sizeof(x)) +#define BLANK(x) memset(x, ' ',sizeof(x)) BLANK(ret->ident); BLANK(ret->cmnt); BLANK(ret->wpt_ident); @@ -257,6 +266,7 @@ GPS_PWay GPS_Way_New(void) ret->facility[0] = 0; ret->addr[0] = 0; ret->wpt_ident[0] = 0; +#endif ret->lat = ret->lon = GPS_FLTMAX; ret->dst = 0; diff --git a/gpsbabel/jeeps/gpssend.c b/gpsbabel/jeeps/gpssend.c index bf7ad86f0..767d921e6 100644 --- a/gpsbabel/jeeps/gpssend.c +++ b/gpsbabel/jeeps/gpssend.c @@ -100,6 +100,17 @@ Diag(void *buf, size_t sz) } } +void +DiagS(void *buf, size_t sz) +{ + unsigned char *cbuf = (unsigned char *) buf; + + while (sz--) { + unsigned char c = *cbuf++; + GPS_Diag("%c", isalnum(c) ? c : '.'); + } +} + /* @func GPS_Write_Packet *********************************************** ** ** Forms a complete packet to send @@ -143,6 +154,11 @@ int32 GPS_Write_Packet(int32 fd, GPS_PPacket packet) Diag(&packet->chk, 3); + + GPS_Diag(": "); + DiagS(packet->data, packet->bytes); + DiagS(&packet->chk, 3); + if((ret=GPS_Serial_Write(fd,(const void *)&packet->chk,(size_t)3)) == -1) { perror("write"); diff --git a/gpsbabel/testo b/gpsbabel/testo index 5d389c016..068822adf 100755 --- a/gpsbabel/testo +++ b/gpsbabel/testo @@ -1,3 +1,5 @@ +GPSBABEL_FREEZE_TIME=y +export GPSBABEL_FREEZE_TIME PNAME=${PNAME:-./gpsbabel} DIFF=${DIFF:-diff} -- 2.30.2